package com.qianfeng.ssmplatform.web.service.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@FeignClient(value = "SSMPLATFORM-CACHE", fallback = CacheServiceFallback.class)
@RequestMapping("/cache")
public interface CacheService {
    //    @RequestMapping(value = "/cache/get/{key}", method = RequestMethod.GET)
//    String get(@PathVariable("key") String key);
//
//    @RequestMapping(value = "/cache/getbject/{key}", method = RequestMethod.GET)
//    Object getObject(@PathVariable("key") String key);
//
//    @RequestMapping(value = "/cache/delete", method = RequestMethod.POST)
//    boolean del(@RequestParam("keys") String... keys);
//
//    @RequestMapping(value = "/cache/hmset/{key}", method = RequestMethod.POST)
//    boolean hmset(@PathVariable("key") String key, @RequestBody Map map);
//
//    @RequestMapping(value = "/cache/hmget/{key}", method = RequestMethod.GET)
//    public Map hmget(@PathVariable("key") String key);
//
//    @RequestMapping(value = "/cache/save2cache", method = RequestMethod.GET)
//    void set(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expireSecond") Long expireSecond);
//
//    @RequestMapping(value = "/cache/save2cache/{key}/{value}", method = RequestMethod.GET)
//    void saveCache(@PathVariable("key") String key, @PathVariable("value") String value);
//
//    @RequestMapping(value = "/cache/incr", method = RequestMethod.GET)
//    public Long incr(@RequestParam("key") String key, @RequestParam("delta") long value);
    @PostMapping("/save2cache")
    public void save2Cache(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam(value = "expireSecond",required = false) Integer expireSecond);

    @PostMapping("/save2cache/{key}/{value}")
    public void save2Cache(@PathVariable String key, @PathVariable String value);


    /**
     * 查询
     *
     * @param key
     * @return
     */
    @GetMapping("/get/{key}")
    public String get(@PathVariable String key);

    /**
     * 如果当时放的是对象,取出来应该转成对象
     *
     * @param key
     * @return
     */
    @GetMapping("/get/object/{key}")
    public Object getObject(@PathVariable String key);

    /**
     * 删除 key
     *
     * @param keys
     * @return
     */
    @DeleteMapping("/delete")
    public Long del(String... keys);

    /**
     * 设置有效期
     *
     * @param key
     * @param seconds
     * @return
     */
    @PostMapping("/expire/{key}/{seconds}")
    public boolean expire(@PathVariable String key, @PathVariable long seconds);


    /**
     * 自增
     *
     * @param key
     * @param delta 步长
     * @return
     */

    @PostMapping("/incr/{key}")
    public long incr(@PathVariable String key, @RequestParam(defaultValue = "1", required = false) long delta);

    /**
     * 自减
     *
     * @param key
     * @param delta
     * @return
     */
    @PostMapping("/decr/{key}")
    public long decr(@PathVariable String key, @RequestParam(defaultValue = "1", required = false) long delta);

    /**
     * 查询 hash 的所有数据
     *
     * @param key
     * @return
     */
    @GetMapping("/hash/{key}")
    public Map<Object, Object> hGetAll(@PathVariable String key);

    /**
     * hash 的存放数据
     *
     * @param key
     * @param map
     */
    @PostMapping("/hash/{key}")
    public void hMset(@PathVariable String key, @RequestBody Map<String, Object> map);

    /**
     * 从 hash 中获取某个属性的值
     *
     * @param key
     * @param field
     * @return
     */
    @GetMapping("/hash/{key}/{field}")
    public Object hget(@PathVariable String key, @PathVariable String field);

    /**
     * 查询 redis 中以符合表达式的 key
     *
     * @param keyPattern
     * @return
     */
    @GetMapping("/keys/{keyPattern}")
    public Set<String> getKeys(@PathVariable String keyPattern);

    /**
     * 向 redis 中存放 zet 数据
     *
     * @param key
     * @param value
     * @param score
     * @return
     */
    @PostMapping("/zset/{key}/{value}/{score}")
    public boolean zAdd(@PathVariable String key, @PathVariable String value, @PathVariable double score);

    @GetMapping("/zset/{key}/{min}/{max}")
    public Set<Object> zRangeByScore(@PathVariable String key, @PathVariable double min, @PathVariable double max);

    @PostMapping("/pipel")
    List<Object> pipelineOps(@RequestBody Map<String, Object> map);
}
